<template>
  <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse"  :default-active="activerouter"
    background-color="#545c64"
    text-color="#fff" :router= "true">
    <h3>后台管理</h3>

    <template v-for="item in menuData" >
      <template v-if="item.children">
        <el-submenu :index="item.lable" :key="item.lable">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span slot="title">{{ item.lable }}</span>
          </template>
          <el-menu-item-group>
            <el-menu-item v-for="item2 in item.children" :index="item2.path" :key="item2.path">
              {{ item2.lable }}
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </template>

      <template v-else>
        <el-menu-item :index="item.path" :key="item.path">
        <!-- <el-menu-item :index="item.name" :key="item.name" @click="clickMenu(item)"> -->
          <i class="el-icon-menu"></i>
          <span slot="title">{{ item.lable }}</span>
        </el-menu-item>
      </template>
    </template>

  </el-menu>
</template>
<style >
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  height: 100vh;
  border-right: 0px;
}
.el-menu h3{
  color: #FFF;
  text-align: center;
  line-height: 48px;
  font-size: 16px;
  font-weight: 400;
  margin-top: 0px;
}
</style>

<script scoped>
export default {
  data() {
    return {
      activerouter:'',
      isCollapse: false,
      menuData: [
        {
          path: '/lunbotu',
          name: 'lunbotu',
          lable: '轮播图管理',
          icon: '',
          url: '/lunbotu'
        },
        {
          path: '/fenlei',
          name: 'fenlei',
          lable: '景点分类',
          icon: '',
          url: '/fenlei'
        },
        {
          path: '/jingdian',
          name: 'jingdian',
          lable: '景点管理',
          icon: '',
          url: '/jingdian'
        },
        {
          path: '/jdsp',
          name: 'jdsp',
          lable: '景点商品',
          icon: '',
          url: '/jdsp'
        },
        {
          path: '/user',
          name: 'user',
          lable: '用户管理',
          icon: '',
          url: '/user'
        },
        {
          path: '/home',
          name: 'home',
          lable: '订单管理',
          icon: '',
          url: '/home'
        },
        {
          path: '/gl',
          name: 'gl',
          lable: '攻略管理',
          icon: '',
          url: '/gl'
        },
        {
          path: '/sq',
          name: 'sq',
          lable: '社区管理',
          icon: '',
          url: '/sq'
        },

        // {
        //   lable: '其他',
        //   icon: '',
        //   children: [
        //     {
        //       path: '/user',
        //       name: 'page1',
        //       lable: '页面1',
        //       icon: '',
        //       url: '/user'
        //     },
        //     {
        //       path: '/page2',
        //       name: 'page2',
        //       lable: '页面2',
        //       icon: '',
        //       url: '/page2'
        //     }
        //   ]
        // }
      ]
    };
  },
  created() {
    //获取地址栏中的路由，设置elementui中的导航栏选中状态
    this.activerouter = this.$route.path;
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    // 点击菜单事件(el-menu的 router属性设置为true 就会自动跳转到for 的index 绑定的地址)
    // clickMenu(item){
    //   //
    //   if(this.$route.path != item.path &&
    //     !(this.$route.path === '/home' && item.path === '/')){

    //   }
    //   this.$router.push(item.path);
    // }
  },

}
</script>